//
//  AppDelegate.m
//  coreBlueTooth
//
//  Created by 刘禹晨 on 5/14/16.
//  Copyright © 2016 刘禹晨. All rights reserved.
//

#import "AppDelegate.h"
#import "MMDrawerController/MMDrawerController.h"
#import "TabViewController.h"
#import "LeftMenuViewController.h"
#import "MMExampleDrawerVisualStateManager.h"
#import "MMDrawerController/UIViewController+MMDrawerController.h"
#import "MMDrawerController/MMDrawerVisualState.h"
#import "MainViewController.h"

#define MaxWidth [UIScreen mainScreen].bounds.size.width
#define MaxHeight [UIScreen mainScreen].bounds.size.height

@interface AppDelegate ()


@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    if(![defaults objectForKey:@"firstStart"])
    {
        // UInt16 socketPort = 9001;
        [defaults setBool:YES forKey:@"firstStart"];
        [defaults setObject:@"10.10.100.254" forKey:@"socketHost"];
        [defaults setInteger:9001 forKey:@"socketPort"];
    }
    //3.强制让数据立刻保存
    [defaults synchronize];
    TabViewController *center = [[TabViewController alloc]init];
//    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];
//    NSLog(@"%@",path);
    LeftMenuViewController *left = [[LeftMenuViewController alloc]init];

    self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:center leftDrawerViewController:left];
    [self.drawerController setShowsShadow:NO];
    //[self.drawerController setRestorationIdentifier:@"MMDrawer"];
    [self.drawerController setMaximumLeftDrawerWidth:MaxWidth / 1.5];
    [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    [self.drawerController setShouldStretchDrawer:false];
    [self.drawerController
            setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
                UIViewController * sideDrawerViewController;
                if(drawerSide == MMDrawerSideLeft){
                    sideDrawerViewController = drawerController.leftDrawerViewController;
                }
                [sideDrawerViewController.view setAlpha:percentVisible];
            }];
    //[self.drawerController setDrawerVisualStateBlock:[MMDrawerVisualState parallaxVisualStateBlockWithParallaxFactor:1.0f]];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

    UIColor * tintColor = [UIColor colorWithRed:29.0/255.0
                                          green:173.0/255.0
                                           blue:234.0/255.0
                                          alpha:1.0];
    [self.window setTintColor:tintColor];
    [self.window setRootViewController:self.drawerController];
    
    [NSThread sleepForTimeInterval:1.8];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    //成功注册registerUserNotificationSettings:后，回调的方法
    NSLog(@"%@",notificationSettings);
}

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    //收到本地推送消息后调用的方法
    NSLog(@"%@",notification);
}

//-(void)closeDrawerAnimated:(BOOL)animated viewController:(UIViewController *)panel completion:(void (^)(BOOL finished))completion
//{
//    NSLog(@"push");
//}

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskPortrait;
}

@end
